import dayjs from 'dayjs'
export default function (app) {
  app.directive('format-time', {
    // created (el, binding, vnode, prenode) {
    //   let formatString = binding.value
    //   if (!formatString) {
    //     formatString = 'YYYY-MM-DD HH:mm:ss'
    //   }
    // },
    mounted (el, binding, vnode, prenode) {
      let formatString = binding.value
      console.log(formatString)
      if (formatString) {
        formatString = 'YYYY-MM-DD hh:mm:ss'
      }
      const text = el.textContent
      console.log('text', text)
      let timestamp = parseInt(text)
      if (timestamp.length === 10) {
        timestamp = timestamp * 1000
      }
      el.textContent = dayjs(timestamp).format('YYYY-MM-DD hh:mm:ss')
    }
  })
}
